package com.xydtech.ecard.ecard.controller;

import com.xydtech.common.enums.ResultStatus;
import com.xydtech.common.model.ResponseModel;
import com.xydtech.common.utils.StringUtils;
import com.xydtech.ecard.ecard.domain.EcardApiShareRecord;
import com.xydtech.ecard.ecard.service.IEcardShareRecordService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 电子名片分享记录Controller
 *
 * @author busiplat
 * @date 2021-09-14
 */
@Controller
@Api(tags = "电子名片-电子名片-分享记录")
@RequestMapping("/ecardSaasApi/share/record")
public class EcardShareRecordController extends EcardApiBaseController {
    @Autowired
    private IEcardShareRecordService ecardShareRecordService;

    /**
     * 电子名片-新增保存电子名片分享记录
     */
    @ApiOperation(value = "电子名片-电子名片分享记录", notes = "电子名片-电子名片分享记录")
    @ApiImplicitParams({@ApiImplicitParam(name = "custmanagerRegistId", value = "电子名片员工微信ID", dataType = "String", dataTypeClass = String.class, paramType = "query", required = true)})
    @ApiResponses({@ApiResponse(code = 0, message = "OK", response = ResponseModel.class)})
    @PostMapping("/addEcardShareRecord")
    @ResponseBody
    public ResponseModel addEcardShareRecord(String custmanagerRegistId) {
        if (StringUtils.isEmpty(custmanagerRegistId)) {
            return ResponseModel.error(ResultStatus.PARAMETER_ERROR);
        }

        EcardApiShareRecord ecardShareRecord = new EcardApiShareRecord();
        //获取当前登录用户信息
        String currentUserId = getCurrentUserId();
        ecardShareRecord.setRegistId(currentUserId);
        ecardShareRecord.setCustmanagerRegistId(custmanagerRegistId);

        int saveCount = ecardShareRecordService.insertEcardShareRecord(ecardShareRecord);
        return saveCount > 0 ? ResponseModel.ok() : ResponseModel.error("插入电子名片分享记录失败！");
    }
}
